The need for increased portability of software programs has resulted in increased development and usage of runtime environments. The term portability refers to the ability to execute a given software program on a variety of computer platforms having different hardware and operating systems. The term “runtime environment” may be referred to as runtime system or virtual machine. The runtime environment allows software programs in source code format to be executed by a target execution platform (i.e., the hardware and operating system of a computer system) in a platform-independent manner. Source code instructions are not statically compiled and linked directly into native or machine code for execution by the target execution platform. Instead, the instructions are statically compiled into an intermediate language (e.g., byte-code) and the intermediate language may then be interpreted or subsequently compiled by a just-in-time (JIT) compiler within the runtime environment into native or machine code that can be executed by the target execution platform.
When compiling intermediate language code, it would be desirable to utilize information obtained from a previous execution of the code to determine how to best optimize the present compilation. A profile of how the code executes may be generated from information sampled from performance counters in a processor executing the code. Determining an appropriate sampling frequency, however, may be challenging. A sampling frequency that is set too high may adversely impact the execution of the code due to the overhead associated with sampling the performance counters. On the other hand, a sampling frequency that is set too low would yield information that is less accurate and less reliable.